import store from '@/store/index'
import { VuexModule, getModule, Module, Mutation, Action } from 'vuex-module-decorators'
import wsCache from '@/cache'
export interface LoginUserState {
  loginUserInfo: object| null
}
@Module({ dynamic: true, namespaced: true, store, name: 'loginUser' })
class LoginUser extends VuexModule implements LoginUserState {
  public userInfoKey = 'userInfo' // 用户信息唯一凭证
  public loginUserInfo = wsCache.get(this.userInfoKey) // 登录信息存储字段
  @Mutation
  private SET_LOGINUSER(loginUserInfo: object|null): void {
    this.loginUserInfo = loginUserInfo
    wsCache.set(this.userInfoKey, loginUserInfo)
  }

  @Action
  public SetLoginUser(loginUserInfo: object): void {
    this.SET_LOGINUSER(loginUserInfo)
  }
}

export const loginUserStore = getModule<LoginUser>(LoginUser)
